package com.easycoding.framework.web;

import java.util.Map;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.easycoding.framework.context.WebContext;

/**
 * <b>Description</b>:WEB上下文环境服务类<br/>

 
 
 
 * <b>Create Date</b>: 2013-3-8 下午5:44:51<br/>
 * <b>Version</b>: Since JDK 1.6.0<br/>
 * <b>Package</b>: com.easycoding.easyweb.framework.web
 */
public class WebContextHelper {
	static Log log = LogFactory.getLog(WebContextHelper.class);
	public final static String REQUEST = "servlet.request";
	public final static String RESPONSE = "servlet.response";
	public final static String SESSION = "servlet.session";
	public final static String SERVLET_CONTEXT = "servlet.servletContext";
	
	/**
	 * 获得当前的请求的servlet request
	 * @return 
	 */
	public static HttpServletRequest  getRequest(){
		Map<String, Object> keeper = WebContext.currentContext().getKeeper();
		
		return (HttpServletRequest) keeper.get(REQUEST);
	}
	/**
	 * 获得当前的请求的servlet Response
	 * @return 
	 */
	public static HttpServletResponse getResponse(){
		Map<String, Object> keeper = WebContext.currentContext().getKeeper();
		
		return (HttpServletResponse) keeper.get(RESPONSE);
	}
	
	/**
	 * 获得当前请求的ServletContext
	 * @return
	 */
	public static ServletContext getServletContext(){
		Map<String, Object> keeper = WebContext.currentContext().getKeeper();
		return (ServletContext) keeper.get(SERVLET_CONTEXT);
	}
	
	/**
	 * 获得当前用户的session
	 * @return
	 */
	public static HttpSession getSession(){
		Map<String, Object> keeper = WebContext.currentContext().getKeeper();
		return (HttpSession) keeper.get(SESSION);
	}
	
	public static Object getSessionVal(String key){
		return getSession().getAttribute(key);
	}
}
